package io;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * 向文件中写入文本数据
 */
public class WriteStringDemo {
    public static void main(String[] args) throws IOException {
        //
        FileOutputStream fos=new FileOutputStream("text.txt",true);
        String line="hello world";
        //字符串转换为字节数组
        byte[] data=line.getBytes(StandardCharsets.UTF_8);
        fos.write(data);

        line="你好";
        fos.write(line.getBytes(StandardCharsets.UTF_8));
        System.out.println("写入完毕!");
        fos.close();
    }
}
